package com.xwh.week3;

public class Practice4 {
    public static void main(String[] args) {
      int [] nums={0,1,2,3,4,5,6,7,8,9};
      for(int i=0;i<=1000000;i++){
          nextPermutation(nums);
      }
        for (int i :nums) {
            System.out.print(i);
        }

    }
    public static void nextPermutation(int[] nums) {
        boolean flag=true;
        if (nums.length==1){
            return;
        }
        int left=0;
        for(int i=nums.length-2;i>=0;i--){
            if(nums[i]<nums[i+1]){
                left=i;
                break;
            }
        }
        for(int j=nums.length-1;j>left;j--){
            if(nums[j]>nums[left]){
                int temp=nums[left];
                nums[left]=nums[j];
                nums[j]=temp;
                flag=false;
                break;
            }
        }
        int right=nums.length-1;
        left=(flag&&left==0)?0:left+1;
        while(left<right){
            int temp=nums[left];
            nums[left]=nums[right];
            nums[right]=temp;
            left++;
            right--;
        }
    }
}
